-- Lua class for managing story_objects. object_id_by_story_id = {} story_id_by_object_id = {} function register(obj_id,story_id) if (object_id_by_story_id[story_id] and object_id_by_story_id[story_id] ~= obj_id) then printf("~ Story Objects | Multiple objects trying to use same story_id %s",story_id) return end object_id_by_story_id[story_id] = obj_id story_id_by_object_id[obj_id] = story_id end function unregister(id) if (story_id_by_object_id[id]) then object_id_by_story_id[story_id_by_object_id[id]] = nil story_id_by_object_id[id] = nil elseif (object_id_by_story_id[id]) then story_id_by_object_id[object_id_by_story_id[id]] = nil object_id_by_story_id[id] = nil end end function check_spawn_ini_for_story_id(se_obj) --printf("checking obj[%s] for story_id!!!",se_obj:name()) local spawn_ini = se_obj:spawn_ini() if not (spawn_ini) then --printf("check_spawn_ini_for_story_id: no spawn ini for %s",se_obj:name()) elseif (spawn_ini:section_exist("story_object")) then local result, id, value = spawn_ini:r_line("story_object",0,"","") --printf("check_spawn_ini_for_story_id: %s | %s = %s",se_obj:name(),id,value) if (id and id ~= "") then -- support for: -- [story_object] -- story_id = some_story_id_string -- ***or*** -- [story_object] -- some_story_id_string if (id == "story_id" and value ~= "") then register(se_obj.id , value) --printf("/ Story Objects 1 | register (%s) = %s", se_obj.id, value) else register(se_obj.id, id) --printf("/ Story Objects 2 | register (%s) = %s", se_obj.id, id) end end return end local story_id = ini_sys:r_string_ex(se_obj:section_name(),"story_id") if story_id ~= nil then register(se_obj.id , story_id) --printf("/ Story Objects 3 | register (%s) = %s", se_obj.id, story_id) end end ----------------------------------------------------------- -- A walk-around for story items since they don't register item_object_id_by_story_id = {} function get_story_se_item(story_id) if (item_object_id_by_story_id[story_id] == nil) then local sim = alife() local found = false for i=1,65534 do local se_obj = sim:object(i) if se_obj and (se_obj:section_name() == story_id) then -- assuming that section is similar to the story id --printf("/ Story Objects | found [%s] with id (%s)", story_id, i) found = i break end end item_object_id_by_story_id[story_id] = found end local id = item_object_id_by_story_id[story_id] return id and alife_object(id) end